# -*- coding: UTF-8 -*-
"""
    剪辑
    @Project ：auto_translate_voice
    @File ：trim_record.py
    @Author ：lc
    @Date ：2022.4.27 16:23
"""
import os
import time

from selenium import webdriver

from config import trim_url, record_audio_path, trim_save_path, file_prefix, last_trim_save_path
from utils import first_trim, trim, save_file, delete_domain_name

webdriver_obj = webdriver.Chrome()
webdriver_obj.maximize_window()
webdriver_obj.get(trim_url)
time.sleep(5)

# 所有配音文件
fileList = os.listdir(record_audio_path)
print("总文件数：", len(fileList))
count = len(fileList)
for file in fileList:
    print("开始剪辑文件：", file)
    first_trim(webdriver_obj, record_audio_path, file)
    trim(webdriver_obj, 'left')
    time.sleep(3)
    trim(webdriver_obj, 'right')
    time.sleep(2)
    # 保存文件
    save_file(webdriver_obj)
    count -= 1
    print("剩余未剪辑文件数：", count)
# 删除域名
delete_domain_name()
# 移动音频
os.system(f"move {trim_save_path}" + os.sep + f"*{file_prefix}* " + last_trim_save_path)
